﻿using System;
using Microsoft.Practices.ObjectBuilder;
using System.Collections.Generic;
using DataContracts;
using System.Web.UI.WebControls;

namespace TrainingWorkshop.MVPWebsite.User.Views
{
	public partial class UpdateUser : Microsoft.Practices.CompositeWeb.Web.UI.Page, IUpdateUserView
	{
		private UpdateUserPresenter _presenter;

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!this.IsPostBack)
			{
				this._presenter.OnViewInitialized();
			}
			this._presenter.OnViewLoaded();
		}

		[CreateNew]
		public UpdateUserPresenter Presenter
		{
			get
			{
				return this._presenter;
			}
			set
			{
				if(value == null)
					throw new ArgumentNullException("value");

				this._presenter = value;
				this._presenter.View = this;
			}
		}

		// TODO: Forward events to the presenter and show state to the user.
		// For examples of this, see the View-Presenter (with Application Controller) QuickStart:
		//	

        protected void EditUpdateButton_Click(object sender, EventArgs e)
        {
            this._presenter.OnUpdateUser();
        }

        public int UserId
        {
            get
            {
                return Convert.ToInt32(Request["UserId"]);
 
            }
        }

        public string FirstName
        {
           
            set { this.EditFirstNameTextBox.Text = value; }
        }
        public string LastName
        {
           
            set { this.EditLastNameTextBox.Text = value; }
        }
        public int DepartmentId
        {
           
            set { this.EditDepartmentDropDownList.SelectedValue = value.ToString(); }
        }
        public string DepartmentName
        {

            set { this.EditDepartmentDropDownList.SelectedItem.Text = value.ToString(); }
        }
        public int RoleId
        {
           
            set { this.EditRoleDropDownList.SelectedValue = value.ToString(); }
        }
        public string RoleName
        {

            set { this.EditRoleDropDownList.SelectedItem.Text = value.ToString(); }
        }
        public string FirstNameUpdate
        {
            get { return this.EditFirstNameTextBox.Text; }
            
        }
        public string LastNameUpdate
        {
            get { return this.EditLastNameTextBox.Text; }
            
        }
        public int DepartmentIdUpdate
        {
            get { return Convert.ToInt32(this.EditDepartmentDropDownList.SelectedValue); }
            
        }
        public string DepartmentNameUpdate
        {
            get { return this.EditDepartmentDropDownList.SelectedItem.ToString(); }
        }
        public int RoleIdUpdate
        {
            get { return Convert.ToInt32(this.EditRoleDropDownList.SelectedValue); }
            
        }
        public string RoleNameUpdate
        {
            get { return this.EditRoleDropDownList.SelectedItem.ToString(); }
        }
        public void SkipToAnotherPage(string address)
        {
            Response.Redirect(address);

        }
        public void ShowOperationMessage(string message)
        {
            //Response.Write("<script>alert('" + message + "')</script>");
            System.Windows.Forms.MessageBox.Show(message, "Error");
        }
        public List<DepartmentDTO> Departments
        {
            set
            {
                this.EditDepartmentDropDownList.DataSource = value;
                EditDepartmentDropDownList.DataTextField = "DepartmentName";
                EditDepartmentDropDownList.DataValueField = "DepartmentId";
                EditDepartmentDropDownList.DataBind();
                EditDepartmentDropDownList.Items.Insert(0, new ListItem("Please Select", "0"));
            }
        }
        public List<RoleDTO> Roles
        {
            set
            {
                this.EditRoleDropDownList.DataSource = value;
                EditRoleDropDownList.DataTextField = "RoleName";
                EditRoleDropDownList.DataValueField = "RoleId";
                EditRoleDropDownList.DataBind();
                EditRoleDropDownList.Items.Insert(0, new ListItem("Please Select", "0"));
            }
        }
}
}

